<!DOCTYPE html>
<html lang="en">

<head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="./vue2.js"></script>
</head>

<body>
    <div id="app">
        <father></father>
    </div>
    <script>
        Vue.component("father", {
            template: `
                <div>
                    <p>父亲年纪多大了，记性不好，我告诉他我叫{{mySonName}}</p>
<son @tellFatherName="getSonName"></son>
                </div>
            `,
            data() {
                return {
                    mySonName: "????"
                }
            },
            methods: {
                getSonName(val) {
                    this.mySonName = val;
                }
            },
            components: {
                son: {
                    template: `
                        <button @click="emitName">点我叫告诉你我的名字叫{{myName}}</button>
                    `,
                    data() {
                        return {
                            myName: "小明"
                        }

                    },
                    methods: {
                        emitName() {
                            this.$emit("tellFatherName", this.myName)
                        }
                    }
                }
            }
        });
        var vm = new Vue({
            el: '#app',
            data: {

            }
        })
    </script>
</body>

</html>